﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HPPUtil;

namespace HPPClientLibrary.DownLoad
{
    [Serializable]
    public class JobInfo
    {
        private string _localFilePath;
        private string _hash;
        private JobStatus _status;
        private int _threadCount;

        private BitArray _localFileBlocks;
        private long _fileLen;//设计图v1.2中没有的
        private string _fileName;//在设计图v1.3中没有的
        private int _blockCount;//块数
        private int _lastBlockLen;


        /// <summary>
        /// 父级DownloadManager的引用
        /// </summary>
        private DownloadManager _manager;

        private object _syncRoot = new object();


        private DownloadJob _downloadJob;

        public DownloadJob DownloadJob
        {
            get
            {
                if (_downloadJob == null)
                {
                    lock (_syncRoot)
                    {
                        if (_downloadJob == null)
                        {
                            _downloadJob = new DownloadJob(this);
                            return _downloadJob;
                        }
                    }
                }
                return _downloadJob;
            }
        }
        public string LocalFilePath
        {
            get { return _localFilePath; }
            set { _localFilePath = value; }
        }
        public BitArray LocalFileBlocks
        {
            get { return _localFileBlocks; }
            set { _localFileBlocks = value; }
        }

        public long FileLen
        {
            get { return _fileLen; }
            set { _fileLen = value; }
        }
        public int BlockAmount
        {
            get { return _blockCount; }
            set { _blockCount = value; }
        }
        public int LastBlockLen
        {
            get { return _lastBlockLen; }
            set { _lastBlockLen = value; }
        }

        public JobInfo(DownloadManager manager, string fileName)//修改:去掉参数:long fileLen @2009.9.9 by WT.wolf  ;//修改:增加参数 string fileName @2009.9.10 by WT.wolf 
        {
            _manager = manager;
            _fileName = fileName;
        }
        public string FileName
        {
            get { return _fileName; }
            set { _fileName = value; }
        }
        public JobStatus Status
        {
            get { return _status; }
            set { _status = value; }
        }
        public string Hash
        {
            get { return _hash; }
            set { _hash = value; }
        }
        public DownloadManager Manager
        {
            get { return _manager; }
            set { _manager = value; }
        }
        public bool Start()
        {
            return DownloadJob.StartDownload();
        }

        public bool Pause()
        {
            return DownloadJob.PauseDownload();
        }

        public bool Stop()
        {
            return DownloadJob.StopDownload();
        }

        public bool Resum()
        {
            return DownloadJob.ResumeDownload();
        }
    }
}
